Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/storage/create_runtime_file.sh

create_runtime_file

Since 0.3.0 · Source

import "{ create_runtime_file }" from nice_things/storage/create_runtime_file.sh

Synopsis
create_runtime_file [-s] [-d | -f | -t] [--] <file>

Configuration

Description
Create a runtime file under process_runtime_dir, or optionally under program_runtime_dir when -s is used.

The <file> operand can optionally include preceding directories. The directories are always created, while the file is not created by default, unless option -f or -t is used.

If <file> contains a path, it must be relative and not start with /, ./ or ../, just the name of the directories leading to the file.

By default, this function creates a path to a file that is exclusive for the current process. This directory is deleted on program exit. The option -s can be used to create a path that is shared by all instances of the current program. Note that, when using -s, multiple processes can interfere with each other.

Options

  • -d: Create a directory instead of a file.
  • -f: Force overwrite an existing file.
  • -s: Use a directory that is shared by all instances of the program.
  • -t: Create the file if it does not exist.

Operands
<file>: Name of the file, with optional relative path.

Stdin

Stdout
Prints the absolute path to the file.

Stderr
log_error.

Exit status

  • 0: Successful completion.
  • 11: Invalid or missing arguments (abort).
  • 14: Base directory missing.
  • 15: Failed to create directory.
  • 16: Failed to write file (when option -f is used).
  • 17: File exists (when option -t is used).

Abort
Aborts on invalid or missing arguments.

Usage examples

# Touch a temporary file
temp_file=$(create_runtime_file -t temp_file.txt)